﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ControlCenter.Data;
using ControlCenter.Model;
using ControlCenter.Model.BizEntities;
using ControlCenter.Model.WebApiDto;
using MingYuanYun.Context.Abstractions;
using MingYuanYun.Data.Abstractions;

namespace ControlCenter.Operation
{
    /// <summary>
    /// 日志操作类
    /// </summary>
    public class LogOperation : OperationBase, ILogOperation
    {
        private readonly IHeartLogRepository _iHeartLogRepository;

        /// <summary>
        /// 类初始化
        /// </summary>
        /// <param name="context"></param>
        /// <param name="unitOfWork"></param>
        public LogOperation(IServiceContext context, IUnitOfWork unitOfWork) : base(context, unitOfWork)
        {
            _iHeartLogRepository = GetRepository<IHeartLogRepository>();
        }

        /// <summary>
        /// 查询最近的心跳日志
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public async Task<IEnumerable<QueryNearLogDto>> QueryNearLogs(DateTime time)
        {
            return await _iHeartLogRepository.QueryNearLogs(time);
        }

        /// <summary>
        /// 批量添加心跳日志
        /// </summary>
        /// <param name="heartLogs"></param>
        /// <returns></returns>
        public async Task<bool> BatchAddHeartLogs(List<HeartLog> heartLogs)
        {
            return await _iHeartLogRepository.BatchAddLogs(heartLogs);
        }
    }
}
